<template>
  <uni-nav-bar title="加注机" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
    :style="{ height: pageHeight + 'px' }">
    <view class="package space-between" v-for="item in fillAll" :key="item.id" style="padding:30rpx 20rpx;">
      <view> {{item.fill_name}}</view>
      <uni-icons type="trash" size="28" @click="del(item.fill_id)"></uni-icons>
    </view>
  </scroll-view>
  <view class="add" @click="navTo('administrator/fleet/addFill')">新增</view>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import { showLoading, successToast, errorToast } from '@/utils/prompt';
  import { navBack, navTo } from '@/utils/navigator';
  import { toPublish } from '@mqtt';
  import { getFleetFillList } from '@/gql/administrator';
  import { onShow } from '@dcloudio/uni-app';
  import { information } from '@/stores/administrator';
  const TeamInfo = information();
  const fillAll = ref()
  const pageHeight = ref();
  uni.getSystemInfo({
    success: function (res) {
      pageHeight.value = res.windowHeight - 120;
    },
  });
  onShow(() => {
    init()
  })
  function init() {
    showLoading()
    const payload = {
      query: getFleetFillList,
      variables: {
        fleet_id: Number(TeamInfo.fleetAll.id)
      },
    };
    toPublish(
      'ql/control/getFleetFillList',
      payload,
      (obj : any) => {
        const { getFleetFillList } = obj.data;
        fillAll.value = getFleetFillList
      }
    );
  }
  function del(id : number) {
    showLoading()
    const payload = {
      fleet_id: Number(TeamInfo.fleetAll.id),
      fill_id: id,
    };
    toPublish(
      'control/delFleetFill',
      payload,
      (obj : any) => {
        const { code, msg } = obj;
        if (code === 1) {
          successToast(msg)
          fillAll.value = fillAll.value.filter((item) => item.fill_id == id ? item = null : item)
        } else {
          errorToast(msg)
        }
      }
    );
  }
</script>

<style scoped lang="less">
  .add {
    width: 480rpx;
    height: 100rpx;
    background: linear-gradient(-10deg, #2C96F9, #1B91FF);
    border-radius: 5px;
    text-align: center;
    line-height: 100rpx;
    color: #fff;
    margin: 20rpx auto;
    font-size: 32rpx;
  }
</style>